import {reactive, ref} from 'vue'
import { defineStore } from 'pinia'
import avatarImg from  "@/assets/panda.png"
import bgImg from  "@/assets/back.png"


export const userStore = defineStore('userStore', () => {

    const userinfo = ref({
        userId: "",
        username : "",
        nickName:"",
        avatar: avatarImg,
        bgImg: bgImg,
    })

    const setUser = (obj) => {
        userinfo.value = {
            ...userinfo.value, // 保留现有值
            ...obj,           // 覆盖传入的新值
            // 确保头像和背景有默认值
            avatar:  obj.avatar ? "/dh" + obj.avatar : avatarImg,
            bgImg:  obj.bgImg ? "/dh" + obj.avatar : bgImg,
        };
    }

    return {setUser, userinfo }
})
